package com.xyy.saas.payment.cores.enums;

import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

/**
 * @author liujf
 * 枚举归并
 */
public class ComEnums {
    @Getter
    public enum BillTypeEnum {
        ORDER(1, "订单"),
        REFUND_ORDER(2,"退款单");
        private Integer code;

        private String name;

        BillTypeEnum(Integer code, String name) {
            this.code = code;
            this.name = name;
        }

        public static String getNameByCode(Integer code) {
            if (ORDER.code.equals(code)) {
                return ORDER.name;
            } else if (REFUND_ORDER.code.equals(code)) {
                return REFUND_ORDER.name;
            } else {
                return null;
            }
        }
    }

    @Getter
    public enum LoanStatusEnum {
        AUDIT_FAIL(1,"AUDIT_FAIL" ,"审核失败"),
        LOANING(2,"LOANING" ,"放款中"),
        LOAN_SUCCESS(3,"LOAN_SUCCESS" ,"放款成功"),
        LOAN_FAIL(4,"LOAN_FAIL" ,"放款失败"),
        OVER_DUE(5,"OVER_DUE" ,"逾期中"),
        FINISH(6,"FINISH" ,"结清"),
        GRACE(7,"GRACE" ,"逾期");
        private Integer code;

        private String thirdCode;

        private String name;

        private static Map<String, LoanStatusEnum> thirdCodeCache = new HashMap<>(7);
        private static Map<Integer, LoanStatusEnum> codeCache = new HashMap<>(7);
        static {
            for (LoanStatusEnum statusEnum : LoanStatusEnum.values()) {
                thirdCodeCache.put(statusEnum.getThirdCode(), statusEnum);
                codeCache.put(statusEnum.getCode(), statusEnum);
            }
        }

        LoanStatusEnum(Integer code,String thirdCode, String name) {
            this.code = code;
            this.thirdCode = thirdCode;
            this.name = name;
        }

        public static Integer getCodeByThirdCode(String thirdCode) {
            if (thirdCode == null) {
                return null;
            }

            LoanStatusEnum statusEnum = thirdCodeCache.get(thirdCode);
            return statusEnum == null ? null : statusEnum.getCode();
        }

        public static String getNameByCode(Integer code) {
            if (code == null) {
                return null;
            }
            LoanStatusEnum statusEnum = codeCache.get(code);
            return statusEnum == null ? null : statusEnum.getName();
        }
    }
}
